package com.eliauk.demo.controller.read;

import com.alibaba.excel.EasyExcel;
import com.eliauk.demo.dao.DemoDAO;
import com.eliauk.demo.entity.read.DemoData;
import com.eliauk.demo.utils.excel.listener.Demo7DataListener;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

@RestController
@RequestMapping("/demo7")
public class demo7Controller {
    /**
     * 读取文件并获取表头数据，其实是在监听器完成，对表头数据操作也都可在监听器中完成（一般没啥用）
     * @param file excel 文件
     * @return
     * @throws IOException
     */
    @PostMapping("/import")
    public String importData(MultipartFile file) throws IOException {
        InputStream in  = file.getInputStream();
        EasyExcel.read(in, DemoData.class,new Demo7DataListener(new DemoDAO()))
                .sheet()
                .doRead();
        return "success";
    }
}
